package com.microstation.controller.system;

import com.microstation.common.AppConst;
import com.microstation.common.Assist;
import com.microstation.common.Result;
import com.microstation.entity.vo.ImgInfoVO;
import com.microstation.enums.ResultEnum;
import com.microstation.service.ImgInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(value = "/api/imgInfo")
public class ImgInfoController extends BaseController {

    @Autowired
    private ImgInfoService imgInfoService;

    @PostMapping(value = "/loadList")
    public Result loadList(@RequestParam(name = "pageIndex", required = true, defaultValue = "0") Integer pageIndex,
                           @RequestParam(name = "limit", required = true, defaultValue = "10") Integer limit) {
        try {
            Assist assist = new Assist();
            assist.setRowSize(limit);
            assist.setPage(pageIndex + 1);
            assist.andEq("del_flag", 1);
            assist.setOrder(Assist.order("id",false));
            Result result = imgInfoService.find(assist);
            return new Result(result.getResults(), result.getRows());
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(Boolean.TRUE, ResultEnum.ERROR.getInfo(), 0L);
        }
    }

    @PostMapping(value = "/saveImgInfo")
    public Result saveImgInfo(ImgInfoVO imgInfoVO) {
        try {
            return imgInfoService.saveImgInfo(imgInfoVO);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(Boolean.TRUE, ResultEnum.ERROR.getType(), e.getMessage(), AppConst.NULL);
        }
    }

    @PostMapping(value = "/removeImgInfo")
    public Result removeImgInfo(String ids) {
        try {
            return imgInfoService.removeImgInfo(ids);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(Boolean.TRUE, ResultEnum.ERROR.getType(), e.getMessage(), AppConst.NULL);
        }
    }
}
